package WordCount

import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.api.scala._

object WordCount {
  def main(args: Array[String]): Unit = {
    //创建一个批处理执行环境
    val env = ExecutionEnvironment.getExecutionEnvironment

    //读取数据
    val inputPath = "src/main/resources/WordCount.txt"
    val inputDateSet = env.readTextFile(inputPath)

    //对数据进行转换处理
    val result = inputDateSet
      .flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(0) //以第一个元素作为key分组
      .sum(1) //第二个元素求和

    //打印输出
    result.print()
  }
}
